import pygame
from pygame.locals import *

from FightWar.Bullet import Bullet
from FightWar.Fly import Fly


class GameMain:
    screen = None
    fly = None
    x = None
    y = None

    @staticmethod
    def start():
        # 创建窗体
        screen = pygame.display.set_mode((450, 600))
        # 加载背景图片
        back = pygame.image.load('./image/back.jpg')
        # 设置标题
        pygame.display.set_caption('打飞机')
        # 添加背景音乐
        pygame.mixer.init()
        pygame.mixer.music.load('./image/bgm.mp3')
        pygame.mixer.music.set_volume(0.3)
        pygame.mixer.music.play(-1)

        # 载入飞机
        fly_pic = pygame.image.load('./image/小飞机.png')
        # 实例化飞机
        fly = Fly()

        # 载入子弹
        buller_pic = pygame.image.load('./image/子弹.png')
        # 实例化子弹
        bullet = Bullet(fly)

        while True:
            screen.blit(back, (0, 0))
            # 显示飞机
            screen.blit(fly_pic, (fly.init_x, fly.init_y))
            fly.move()

            # 显示子弹
            screen.blit(buller_pic, (bullet.init_x, bullet.init_y))
            bullet.move(fly)
            # 更新显示内容
            pygame.display.update()
        pass

    @staticmethod
    def control_time():
        clock = pygame.time.Clock()
        print(clock)

if __name__ == '__main__':
    #GameMain.control_time()
    GameMain.start()
